package com.example.cyk.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.example.cyk.myapplication.utils.PopupUtils;


public class MyActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        Log.i("log", "onCreate");
    }

    public void onNextActivity(View v){
        Intent intent  = new Intent(this, SecondActivity.class);
        startActivity(intent);
    }
    public void OnMyButtonClicked(View v)
    {
        TextView tv = (TextView) findViewById(R.id.id_button);
        tv.setText("Button Click!!");
    }
    public void imgClicked(View v)
    {
        Log.i("log", "imgClicked");
        PopupUtils popup = new PopupUtils(this);
        popup.onToast("imgClicked");
        Animation ani = AnimationUtils.loadAnimation(this, R.anim.rotation);
        v.startAnimation(ani);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my, menu);
        Log.i("log", "onCreateOptionsMenu");
        return true;
    }
    /*
    @Override
    public boolean onKeyDown( int KeyCode, KeyEvent event ){
        switch(KeyCode){
            case KeyEvent.KEYCODE_BACK:
                PopupUtils popup = new PopupUtils(this);
                popup.onExitPopup("프로그램을 종료하겠습니까?");
        }
        return true;
    }
    */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        PopupUtils popup = new PopupUtils(this);
        if (id == R.id.action_onPopup) {
            popup.onPopup("한글", "한글");
            return true;
        }
        if (id == R.id.action_onExitPopup) {
            popup.onExitPopup("Are you sure you want to exit?");
            return true;
        }
        if (id == R.id.action_onListPopup) {
            final CharSequence[] items = {"Red", "Green", "Blue"};
            popup.onListPopup("Pick a color", items);
            return true;
        }
        if (id == R.id.action_onCheckPopup) {
            final CharSequence[] items = {"Red", "Green", "Blue"};
            final boolean[] itemsChecked = {false, true, false};
            popup.onCheckPopup("Pick a color", items, itemsChecked);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
